<%--
  Created by IntelliJ IDEA.
  User: 步步为莹
  Date: 2019/9/17
  Time: 9:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Beyond车辆管理平台</title>
    <link rel="stylesheet" href="../../static/css/style.css">
    <link rel="stylesheet" href="../../static/css/jquery.wysiwyg.old-school.css">
    
    <!-- jQuery AND jQueryUI -->
    <script type="text/javascript" src="../../static/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../static/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../../static/js/min.js"></script>
    <script type="text/javascript" src="../../static/js/common.js"></script>
    <!--<script type="text/javascript" src="js/index.js"></script>-->
</head>
<body>
<script type="text/javascript" src="../../static/js/main.js"></script>
<link rel="stylesheet" href="../../static/css/style2.css">
<div id="content" class="white">
    <h1><img src="../../static/images/users1.png" alt="">驾照管理</h1>
    <!--操作栏-->
    <div class="bloc">
        <div class="title"> 操作 <a class="toggle"></a></div>
        <div class="content dashboard">
            <div class="center" style="display: block; width: auto;">
                <a href="javascript:;" onclick="add()">新增驾照</a>
                <a href="javascript:;">
                    批量删除 </a>
            </div>
        </div>
    </div>
    
    <div class="bloc">
        <div class="title">驾照列表</div>
        <div class="content">
            <table>
                <thead>
                <tr>
                    <th><input type="checkbox" id="selectALL" onclick="selectAll(this)">全选</th>
                    <th>驾照编号</th>
                    <th>驾驶员</th>
                    <th>发证日期</th>
                    <th>驾校名称</th>
                    <th>驾驶车辆类型</th>
                </tr>
                </thead>
                <tbody id="listdrivingLicense">
                
                </tbody>
            </table>
        </div>
    </div>
</div>
<div id="ui-datepicker-div"
     class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>
<script type="text/javascript">

    var options=new Array();
    <c:forEach var="option" items="${optionlist}">
    var dictionary={"type":"${option.type_Id}","value":${option.value},"name":"${option.name}"};
    options.push(dictionary);
    </c:forEach>
    
    //加载角色列表
    $.ajax({
        url: "<%=request.getContextPath()%>/drivingLicenseServlet",
        type: "POST",
        data: "opr=listDrivingLicense",
        success: function (result) {
            console.log(result);
            var stuUser = "";
            $.each(result, function (index, ele) {
                console.log(ele);
                stuUser += "<tr>";
                stuUser += "<td><input type='checkbox' class='UserId'><input type='hidden' value='" + ele.id + "'> </td>"
                stuUser += "<td>" + ele.driving_license_No + "</td>";
                stuUser += "<td>" + ele.driver_id + "</td>";
                stuUser += "<td>" + ele.opening_date + "</td>";
                stuUser += "<td>" + ele.driver_school + "</td>";
                stuUser += "<td>" + getDictionary("vehicleType",ele.drive_type,options) + "</td>";
                stuUser += "<td><a href='javascript:;' title='修改' onclick='update(this)'>\n" +
                    "<img src='../../static/images/edit.png'></a>\n" +
                    "<a href='javascript:;' title='删除' onclick='del(this)'>\n" +
                    "<img src='../../static/images/delete.png'></a></td>";
                stuUser += "</tr>";
            });
            $("tbody#listdrivingLicense").append(stuUser);
        }

    });


    //其他复选框取消选中时全选取消
    function checkFalse(obj) {
        if (!$(this).is(":checked")) {
            $("#selectALL").prop("checked", false);
        }
    }

    //全选
    function selectAll(obj) {
        //prop() 方法设置或返回被选元素的属性和值
        if ($(obj).is(':checked')) {
            $(":checkbox").prop("checked", true);
        } else {
            $(":checkbox").prop("checked", false);
        }
    };
    //增加
    function add() {
        window.location.href="driving_licenseAdd.jsp";
        
    }
    //修改
    function update(obj) {
        var Id=$(obj).parent().siblings("td").children("[type='hidden']").val();
        console.log(Id);
        window.location.href="driving_licenseUpdate.jsp?id="+Id;
        
    }
    //删除单个员工
    function  del(obj) {
        var userId=$(obj).parent().siblings("td").children("[type='hidden']").val();
        var confirm=window.confirm("确定删除吗？")
        if (confirm===true){
            $.ajax({
                url:"<%=request.getContextPath()%>/drivingLicenseServlet",
                data:"Id="+userId+"&opr=deleteDrivingLicense",
                dataType:"text",
                type:"GET",
                success:function (result) {
                    console.log(result)
                    if (result=='true'){
                        alert("删除成功！");
                        window.location.reload();
                    }else {
                        alert("删除失败！");
                    }
                }
            })
        }
    }
    
</script>

</body>
</html>
